<?php
require_once("./session.php");
require_once("../include/global.php");

if(empty($_GET['action']))
{
	print <<<HTML
	<div id="commentlist" style="width:100%; margin:0 auto;padding-bottom:15px;">
	<div class="admin_title">评论管理</div>
HTML;
	
	/***********************************************************************************************************/
	/*	显示分页
	/***********************************************************************************************************/
	$sqlCount = "select count(*) from blog_comment";
	$curpage = 0;
	DoPage($sqlCount, $pagesize, $curpage, "$phpself?do=comments");
	/***********************************************************************************************************/
	
	print <<<HTML
	<div id="content" style="width:100%; margin-top:10px;">
	<table width="740" border="1" cellpadding="0" cellspacing="0" bordercolor="#ffffff">
	<form name="comments" method="post">
		<tr style="background:#6784A4">
			<td width="22" align="center"><input name="selectall" type="checkbox" id="selectall" onclick="CheckAllBoxes('comments');" /></td>
			<td width="40" height="25" align="center">ID</td>
			<td width="100" align="center">评论内容</td>
			<td width="100" align="center">评论者</td>
			<td width="200" align="center">发表时间</td>
			<td width="100" align="center">所属文章</td>
			<td width="100" align="center">IP</td>
			<td align="center">操作</td>
		</tr>\n
HTML;

	$sqlData = "SELECT log.log_Title, comm.* 
				FROM blog_comment as comm, blog_article as log
				WHERE log_ID = comm_LogID order by comm_PostTime desc limit ".(($curpage-1)*$pagesize).",".$pagesize;
	$result = mysql_query($sqlData) or die(mysql_error());
	$num = 1;
	while($rs = mysql_fetch_object($result))
	{
		$time = strftime("%B %d,%Y,%H:%M %p",$rs->comm_PostTime);
	print <<<HTML
		<tr>
			<td height="20" align="center"><input name="select1" type="checkbox" id="select" name="select" /></td>
			<td align="center">$rs->comm_ID<input name="comm_ID" type="hidden" value="$rs->comm_ID" /></td>
			<td align="center"><input name="comm_Content" type="text" value="$rs->comm_Content" /></td>
			<td align="center">$rs->comm_Author</td>
			<td align="center">$time</td>
			<td align="center">$rs->log_Title</td>
			<td align="center">$rs->comm_PostIP</td>
			<td width="30" align="center"><a href="$phpself?do=comments&action=delete&comm_ID=$rs->comm_ID" >
			<img src="./images/icon_del.gif" alt="删除" width="16" height="16" />
			</a></td>
		</tr>\n
HTML;
		 $num++;
	}
	echo "</form>\n</table>";
	
	/***********************************************************************************************************/
	/*	显示分页
	/***********************************************************************************************************/
	DoPage($sqlCount, $pagesize, $curpage, "$phpself?do=comments");
	/***********************************************************************************************************/
	
	print <<<HTML
	</div>\n
	</div>
HTML;
	
}
/***********************************************************************************************************/
/*	处理编辑或删除请求
/***********************************************************************************************************/
else
{
    switch($_GET['action'])
	{
	    case 'delete':
		   if(!empty($_GET['comm_ID']) && is_numeric($_GET['comm_ID']))
		   {  
		        DelComment($_GET['comm_ID']);
				echo "<script>location.href='main.php?do=comments';</script>"; 
		   }
		   break;
		   
		default:break;
	}
}
?>
